<template>
  <div>
    <jxf-titletip title="次月额度发放记录" :hasRefresh="false" :hasGoBack="true" @goBack="$emit('update:isShowGrantLog', false)"></jxf-titletip>
    <el-card class="jxf-table-card mt20">
      <div slot="header" class="clearfix">
        <span>数据列表</span>
      </div>
      <jxf-table class="" :table="tableInfo">
        <template slot="status" slot-scope="scope">
          <span>{{scope.row.status === 0 ? '待放款': scope.row.status === 1 ? '通过，发放额度 ' + scope.row.credit : ''}}</span>
        </template>
        <template slot="star" slot-scope="scope">
          <el-row type="flex" vertical="start">
            <el-col style="width: auto">
              <el-rate v-model="scope.row.star" disabled text-color="#ff9900" score-template="{value}"></el-rate>
            </el-col>
            <el-col style="width: auto">{{scope.row.score}}分</el-col>
          </el-row>
        </template>
      </jxf-table>
    </el-card>
  </div>
</template>

<script>
  import formatDate from '@/assets/js/formatDate'
  export default {
    props: {
      isShowGrantLog: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        tableInfo:{}
      }
    },
    methods: {
      init(){
        this.tableInfo = {
          border: true,
          loading: true,
          tr: [
            {
              id: '1',
              label: '企业名称',
              prop: 'enterpriseName'
            },
            {
              id: '3',
              label: '评分等级',
              show: 'template',
              width: "180",
              prop: 'star'
            },
            {
              id: '4',
              label: '审核次月额度',
              minWidth: "120",
              prop: 'beforeCredit'
            },
            {
              id: '5',
              label: '发放记录',
              show: 'template',
              prop: 'status'
            },
            {
              id: '6',
              label: '账期',
              prop: 'accountPeriod'
            },
            {
              id: '7',
              label: '操作人',
              prop: 'auditName'
            },
            {
              id: '8',
              label: '备注',
              prop: 'remark'
            },
            {
              id: '9',
              label: '操作时间',
              width: '160',
              prop: 'auditTime'
            }
          ],
          data: []
        }
      },
      getGrantLog(id) {
        ajax.get(apis.factory.creditRecord, {id:id})
          .then(res => {
            if (res.success === true && res.data !== null) {
              this.tableInfo.data = this.formatData(res.data)
            }else {
              this.tableInfo.data = []
            }
            this.tableInfo.loading = false
          })
      },
      // 列表数据处理
      formatData(item) {
        return [{
          id: item.id,
          enterpriseName: item.enterpriseName,
          star: item.star,
          beforeCredit: item.beforeCredit,
          credit: item.credit,
          auditName: item.auditName,
          auditTime: formatDate.timeFormat(item.auditTime),
          accountPeriod: item.accountPeriod !== null ? item.accountPeriod + '个月' :"",
          remark: item.remark,
          score: item.score,
          status: item.status
        }]
      }
    },
    created() {
      this.init()
    }
  }
</script>

<style lang="scss" scoped>
</style>
